package demo

import (
	"common_demo/internal/service"
	"context"
	"net/http"

	"github.com/gin-gonic/gin"
)

type DemoHandler struct {
	*service.ServiceGroup
}

func NewDemoHandler(ctx context.Context) *DemoHandler {
	return &DemoHandler{
		service.NewServiceGroup(ctx),
	}
}

func (handler *DemoHandler) AddThings(ctx *gin.Context) {
	var requestBody struct{}

	if err := ctx.ShouldBindJSON(&requestBody); err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	err := handler.AddThing(requestBody)
	if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
	} else {
		ctx.JSON(http.StatusOK, gin.H{"message": "success"})
	}
}
